from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-09-02 14:03:24.770898
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 02, Sep, 2022
Time: 14:03:31
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.2933
Nobs: 767.000 HQIC: -50.6284
Log likelihood: 9791.48 FPE: 8.34258e-23
AIC: -50.8381 Det(Omega_mle): 7.42454e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.300259 0.054613 5.498 0.000
L1.Burgenland 0.106533 0.036338 2.932 0.003
L1.Kärnten -0.106760 0.019307 -5.530 0.000
L1.Niederösterreich 0.206736 0.076038 2.719 0.007
L1.Oberösterreich 0.113460 0.073594 1.542 0.123
L1.Salzburg 0.253036 0.038884 6.507 0.000
L1.Steiermark 0.036028 0.050693 0.711 0.477
L1.Tirol 0.106910 0.041065 2.603 0.009
L1.Vorarlberg -0.060792 0.035306 -1.722 0.085
L1.Wien 0.049420 0.065420 0.755 0.450
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.060650 0.113460 0.535 0.593
L1.Burgenland -0.034952 0.075494 -0.463 0.643
L1.Kärnten 0.047362 0.040111 1.181 0.238
L1.Niederösterreich -0.175927 0.157970 -1.114 0.265
L1.Oberösterreich 0.395034 0.152894 2.584 0.010
L1.Salzburg 0.290411 0.080782 3.595 0.000
L1.Steiermark 0.105710 0.105316 1.004 0.316
L1.Tirol 0.314473 0.085313 3.686 0.000
L1.Vorarlberg 0.026985 0.073348 0.368 0.713
L1.Wien -0.022473 0.135911 -0.165 0.869
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.191093 0.028061 6.810 0.000
L1.Burgenland 0.089637 0.018671 4.801 0.000
L1.Kärnten -0.008648 0.009920 -0.872 0.383
L1.Niederösterreich 0.260145 0.039069 6.659 0.000
L1.Oberösterreich 0.134332 0.037814 3.552 0.000
L1.Salzburg 0.045796 0.019979 2.292 0.022
L1.Steiermark 0.018328 0.026047 0.704 0.482
L1.Tirol 0.093440 0.021100 4.428 0.000
L1.Vorarlberg 0.058309 0.018141 3.214 0.001
L1.Wien 0.118640 0.033614 3.530 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.108293 0.028533 3.795 0.000
L1.Burgenland 0.047562 0.018986 2.505 0.012
L1.Kärnten -0.014758 0.010087 -1.463 0.143
L1.Niederösterreich 0.191623 0.039727 4.823 0.000
L1.Oberösterreich 0.290032 0.038450 7.543 0.000
L1.Salzburg 0.111506 0.020315 5.489 0.000
L1.Steiermark 0.102857 0.026485 3.884 0.000
L1.Tirol 0.110543 0.021455 5.152 0.000
L1.Vorarlberg 0.069683 0.018446 3.778 0.000
L1.Wien -0.018065 0.034180 -0.529 0.597
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.130953 0.051814 2.527 0.011
L1.Burgenland -0.051355 0.034476 -1.490 0.136
L1.Kärnten -0.040306 0.018317 -2.200 0.028
L1.Niederösterreich 0.170007 0.072140 2.357 0.018
L1.Oberösterreich 0.140480 0.069822 2.012 0.044
L1.Salzburg 0.288151 0.036891 7.811 0.000
L1.Steiermark 0.032822 0.048094 0.682 0.495
L1.Tirol 0.161967 0.038960 4.157 0.000
L1.Vorarlberg 0.100357 0.033496 2.996 0.003
L1.Wien 0.068837 0.062066 1.109 0.267
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.055823 0.041254 1.353 0.176
L1.Burgenland 0.040350 0.027450 1.470 0.142
L1.Kärnten 0.050428 0.014584 3.458 0.001
L1.Niederösterreich 0.220339 0.057438 3.836 0.000
L1.Oberösterreich 0.282533 0.055593 5.082 0.000
L1.Salzburg 0.045401 0.029373 1.546 0.122
L1.Steiermark -0.000474 0.038293 -0.012 0.990
L1.Tirol 0.148055 0.031020 4.773 0.000
L1.Vorarlberg 0.072933 0.026670 2.735 0.006
L1.Wien 0.085389 0.049418 1.728 0.084
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.179548 0.049401 3.634 0.000
L1.Burgenland -0.005937 0.032871 -0.181 0.857
L1.Kärnten -0.061334 0.017464 -3.512 0.000
L1.Niederösterreich -0.084022 0.068782 -1.222 0.222
L1.Oberösterreich 0.196393 0.066571 2.950 0.003
L1.Salzburg 0.056394 0.035173 1.603 0.109
L1.Steiermark 0.230948 0.045855 5.036 0.000
L1.Tirol 0.494038 0.037146 13.300 0.000
L1.Vorarlberg 0.047946 0.031937 1.501 0.133
L1.Wien -0.051845 0.059177 -0.876 0.381
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.166381 0.056732 2.933 0.003
L1.Burgenland -0.010328 0.037748 -0.274 0.784
L1.Kärnten 0.067110 0.020056 3.346 0.001
L1.Niederösterreich 0.206411 0.078987 2.613 0.009
L1.Oberösterreich -0.071165 0.076449 -0.931 0.352
L1.Salzburg 0.211537 0.040392 5.237 0.000
L1.Steiermark 0.115689 0.052659 2.197 0.028
L1.Tirol 0.072025 0.042658 1.688 0.091
L1.Vorarlberg 0.121540 0.036675 3.314 0.001
L1.Wien 0.122401 0.067958 1.801 0.072
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.358019 0.032786 10.920 0.000
L1.Burgenland 0.005618 0.021815 0.258 0.797
L1.Kärnten -0.023195 0.011591 -2.001 0.045
L1.Niederösterreich 0.215247 0.045648 4.715 0.000
L1.Oberösterreich 0.187894 0.044181 4.253 0.000
L1.Salzburg 0.046035 0.023343 1.972 0.049
L1.Steiermark -0.015775 0.030433 -0.518 0.604
L1.Tirol 0.106488 0.024653 4.320 0.000
L1.Vorarlberg 0.073437 0.021195 3.465 0.001
L1.Wien 0.047632 0.039274 1.213 0.225
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.040034 0.148601 0.192340 0.157598 0.124358 0.113272 0.065927 0.222201
Kärnten 0.040034 1.000000 -0.003921 0.132687 0.041508 0.095793 0.430813 -0.052325 0.100447
Niederösterreich 0.148601 -0.003921 1.000000 0.338311 0.151670 0.297949 0.107313 0.183398 0.323628
Oberösterreich 0.192340 0.132687 0.338311 1.000000 0.228352 0.330848 0.172464 0.167987 0.264339
Salzburg 0.157598 0.041508 0.151670 0.228352 1.000000 0.147771 0.122273 0.147403 0.133242
Steiermark 0.124358 0.095793 0.297949 0.330848 0.147771 1.000000 0.151399 0.138586 0.079503
Tirol 0.113272 0.430813 0.107313 0.172464 0.122273 0.151399 1.000000 0.115182 0.153028
Vorarlberg 0.065927 -0.052325 0.183398 0.167987 0.147403 0.138586 0.115182 1.000000 0.006828
Wien 0.222201 0.100447 0.323628 0.264339 0.133242 0.079503 0.153028 0.006828 1.000000